<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<div class="row">
    <!-- NEW WIDGET START -->
    <article class="col-sm-12 col-md-12 col-lg-12">
        <div class="jarviswidget well" id="wid-id-3"
             data-widget-colorbutton="false"
             data-widget-editbutton="false"
             data-widget-togglebutton="false"
             data-widget-deletebutton="false"
             data-widget-fullscreenbutton="false"
             data-widget-custombutton="false"
             data-widget-sortable="false">
            <!-- widget div-->
            <div>
                <div class="widget-body">
                    <a class="btn btn-default" id="btn-re-common" href="javascript:void(0)">
                        <i class="fa fa-lg fa-mail-reply-all"></i> 项目立项
                    </a>

                    <s:if test="proStart==null || proStart.getProcessState().name()=='Draft'">
                        <a class="btn btn-default pull-right pull-right-fix" id="btn-confirm-common" href="javascript:void(0);"><i class="fa fa-rocket"></i> 提交</a>
                    </s:if>
                    <s:if test="proStart.getProcessState().name()=='Backed'">
                        <a class="btn btn-default pull-right pull-right-fix" id="btn-recommit-common" href="javascript:void(0);"><i class="fa fa-rocket"></i> 再提交</a>
                    </s:if>

                    <a class="btn btn-default pull-right pull-right-fix" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存</a>

                    <hr class="simple">

                    <form id="proStart" class="smart-form" novalidate="novalidate" action="" method="post">
                        <input type="hidden" name="keyId" id="keyId" value="<s:property value="proStart.id" />"/>
                        <input type="hidden" name="curDutyId" id="curDutyId" value="<s:property value="curDutyId" />"/>

                        <header id="title" style="display: block;">
                            项目立项表
                            <a aria-disabled="isAdd(keyId)" href="javascript:void(0);" key="btn-comment">
                                    <span class="txt-color-blueDark pull-right">
                                        <i class="fa-fw fa fa-comment-o"></i> 审批意见<span></span>
                                    </span>
                            </a>
                        </header>
                        <fieldset>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    项目名称
                                </label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input type="text" name="name" id="name" placeholder="请输入项目名称" value="<s:property value="proStart.name"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    项目简称
                                </label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input type="text" name="subname" id="subname" placeholder="请输入项目简称" value="<s:property value="proStart.subname"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    是否委托中介机构
                                </label>
                                <section class="col col-5">
                                    <div class="inline-group" >
                                        <label class="radio" >
                                            <input type="radio" name="isDelegate" value="1" <s:property value="proStart.isDelegate==1?'checked':''"/>>
                                            <i></i>是
                                        </label>
                                        <label class="radio" >
                                            <input type="radio" name="isDelegate" value="0" <s:property value="proStart==null?'checked':proStart.isDelegate==0?'checked':''"/>>
                                            <i></i>否
                                        </label>
                                    </div>
                                </section>
                            </div>

                            <div class="row" id="agentDiv" style="display: <s:property value="(proStart==null||proStart.isDelegate==0)?'none;':'block;'"/>">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    中介机构名称
                                </label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input name="agentName" id="agentName" placeholder="请输入中介机构名称"
                                               type="text" value="<s:property value="proStart.agentName"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">项目性质</label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input name="type" id="type" placeholder="请输入项目性质"
                                               type="text" value="<s:property value="proStart.type"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">项目大致建设内容</label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input name="content" id="content" placeholder="请输入项目大致建设内容"
                                               type="text" value="<s:property value="proStart.content"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">项目建设地点</label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input name="locate" id="locate" placeholder="请输入项目建设地点"
                                               type="text" value="<s:property value="proStart.locate"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">项目预计开始时间</label>
                                <section class="col col-2">
                                    <label class="input">
                                        <i class="icon-append fa fa-calendar"></i>
                                        <input  class="hasDatepicker form-control" name="start" id="start" placeholder="请选择项目预计开始时间"
                                               type="text" value="<s:date name="proStart.start" format="yyyy-MM-dd"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">项目预计完成时间</label>
                                <section class="col col-2">
                                    <label class="input">
                                        <i class="icon-append fa fa-calendar"></i>
                                        <input class="hasDatepicker form-control"  name="end" id="end" placeholder="请选择项目预计完成时间"
                                               type="text" value="<s:date name="proStart.end" format="yyyy-MM-dd"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">立项批复文件上传</label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input  name="uploadify" id="filename" placeholder="" type="file" >
                                        <input name="fileId" id="fileId" style="display: none" value="<s:property value="proStart.fileReplyId"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">项目批复金额</label>
                                <section class="col col-4">
                                    <label class="input">
                                        <input name="replayMoney" id="replayMoney" placeholder="项目批复金额"
                                               type="number" value="<s:property value="proStart.replayMoney"/>">
                                    </label>
                                </section>
                                <label class="label col money-unit-form">万元</label>
                            </div>
                            <div class="row">
                                <label class="label col col-2">批复日期</label>
                                <section class="col col-2">
                                    <label class="input">
                                        <i class="icon-append fa fa-calendar"></i>
                                        <input class="hasDatepicker form-control" name="replyDate" id="replyDate" placeholder="请输入批复日期"
                                               type="text" value="<s:date name="proStart.replyDate" format="yyyy-MM-dd"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">相关文号</label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input name="no" id="no" placeholder="请输入相关文号"
                                               type="text" value="<s:property value="proStart.no"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">备注</label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input name="mark" id="mark" placeholder="请输入备注"
                                               type="text" value="<s:property value="proStart.mark"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">提交人</label>
                                <section class="col col-2">
                                    <label class="input state-disabled">
                                        <input value="<s:property value="procreater.name"></s:property> " placeholder="" type="text" disabled="disabled">
                                    </label>
                                </section>
                                <label class="label col col-1">提交日期</label>
                                <section class="col col-2">
                                    <label class="input state-disabled">
                                        <input value="<s:date name="proStart.getCreateDate()" format="yyyy-MM-dd"></s:date> " placeholder="" type="text" disabled="disabled" >
                                    </label>
                                </section>
                            </div>

                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </article>
</div>

<script>

    //返回视图
    $("#btn-re-common").click(function(){
        loadURL("ajax!prostart.action",$('#content'));
    });
    //左侧意见栏
    $("a[key=btn-comment]").unbind("click").bind("click",function(){
        var keyId = $("input#keyId").val();
        var actionUrl = "ajax-running!comment.action?bussinessId="+keyId;
        $(this).leftview('init',{
            title:"查看评论",
            actionUrl:actionUrl
        });
    })
    //校验
    $("#proStart").validate({
        rules : {
            name : {
                required : true
            },
            agentName:{
                required : true
            }
        },
        messages : {
            name : {
                required : '请输入用户名'
            },
            agentName:{
                required : '请输入中介机构名称'
            }

        },
        errorPlacement : function(error, element) {
            error.insertAfter(element.parent());
        }
    });

    $('.hasDatepicker').datetimepicker({
        format: 'yyyy-mm-dd',
        weekStart: 1,
        autoclose: true,
        todayBtn: 'linked',
        language: 'zh-CN',
        minView:2
    });
    //保存
    $("#btn-save-common").click(
            function(e) {
                $.SmartMessageBox({
                    title : "提示：",
                    content : "确定提交申请吗？",
                    buttons : '[取消][确认]'
                }, function(ButtonPressed) {
                    if (ButtonPressed === "取消") {
                        e.preventDefault();
                        e.stopPropagation();
                        return;
                    }
                    if (ButtonPressed === "确认") {
                        $("#btn-save-common").attr("disabled", "disabled");
                        form_save("proStart","<%=path%>/com/ajax-prostart!save.action");
                        loadURL("ajax!prostart.action",$('#content'));
                    }
                });
            }
    );
    //提交
    $("#btn-confirm-common").click(
            function(e) {
                var $valid = $("#proStart").valid();

                if(!$valid){
                    e.preventDefault();
                    e.stopPropagation();
                    return;
                }
                $.SmartMessageBox({
                    title : "提示：",
                    content : "确定提交申请吗？",
                    buttons : '[取消][确认]'
                }, function(ButtonPressed) {
                    if (ButtonPressed === "取消") {
                        e.preventDefault();
                        e.stopPropagation();
                        return;
                    }
                    if (ButtonPressed === "确认") {
                        var $validForm = $("#proStart").valid();
                        if(!$validForm) return false;
                        $("#btn-confirm-common").attr("disabled", "disabled");
                        form_save("proStart","<%=path%>/com/ajax-prostart!commit.action?comment="+$("textarea#chat_textarea-expand").val());
                        loadURL("ajax!prostart.action",$('#content'));
                    }
                });
            }
    );
    $("#btn-recommit-common").unbind().bind("click",function(e){
        var $valid = $("#proStart").valid();

        if(!$valid){
            e.preventDefault();
            e.stopPropagation();
            return;
        }
        $.SmartMessageBox({
            title : "提示：",
            content : "确定再次提交申请吗？",
            buttons : '[取消][确认]'
        }, function(ButtonPressed) {
            if (ButtonPressed === "取消") {
                e.preventDefault();
                e.stopPropagation();
                return;
            }
            if (ButtonPressed === "确认") {
                var $validForm = $("#proStart").valid();
                if(!$validForm) return false;
                $("#btn-recommit-common").attr("disabled", "disabled");
                form_save("proStart","<%=path%>/com/ajax-prostart!commit.action");
                loadURL("ajax!prostart.action",$('#content'));
            }
        });
    });
</script>
<script type="text/javascript">
    //上传文件
    inputLoad({
        objId:"filename",
        entityName:"fileReplyId",
        sourceId:"fileId"
    });

    $(function(){
        var pdata= {
            keyId:$("#keyId").val(),
            flowName:"proStart"
        };
        multiDuty(pdata);
    });
    $("input[name=isDelegate]").unbind().bind("click",function(e){
        $("#agentName").val("");
        if($(this).prop("checked") && $(this).val() == "1"){
            $("#agentDiv").show();
        }else{
            $("#agentDiv").hide();
        }
    });

</script>
